@model IEnumerable<UpdaterManagement.Models.Product>

<nav aria-label="breadcrumb" class="breadcrumb-ace">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/">首页</a></li>
        <li class="breadcrumb-item active">产品管理</li>
    </ol>
</nav>

<div class="page-header">
    <div class="d-flex justify-content-between align-items-center">
        <div>
            <h1 class="page-title">
                <i class="bi bi-box-seam text-primary me-2"></i>产品管理
            </h1>
            <p class="page-subtitle">管理系统中的所有产品信息，支持IIS站点和Windows服务</p>
        </div>
        <a href="/Product/Create" class="btn btn-ace-primary">
            <i class="bi bi-plus-circle me-2"></i>新增产品
        </a>
    </div>
</div>

<div class="card-ace mb-3">
    <div class="card-body">
        <form method="get" class="row g-3">
            <div class="col-md-4">
                <label class="form-label-ace">部门查询</label>
                <select class="form-select form-control-ace" name="departmentId">
                    <option value="">全部部门</option>
                    @foreach (var dept in ViewBag.Departments as List<UpdaterManagement.Models.Department>)
                    {
                        <option value="@dept.Id" selected="@(ViewBag.DepartmentId?.ToString() == dept.Id.ToString())">@dept.Name</option>
                    }
                </select>
            </div>
            <div class="col-md-2">
                <label class="form-label-ace">&nbsp;</label>
                <div>
                    <button type="submit" class="btn btn-ace-primary me-2">
                        <i class="bi bi-search me-1"></i>查询
                    </button>
                    <a href="/Product" class="btn btn-outline-secondary">
                        <i class="bi bi-arrow-clockwise me-1"></i>重置
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="row mb-4">
    <div class="col-xl-3 col-md-6">
        <div class="stat-card">
            <div class="stat-icon text-primary">
                <i class="bi bi-collection"></i>
            </div>
            <div class="stat-number text-primary">@ViewBag.TotalCount</div>
            <div class="stat-label">总产品数</div>
        </div>
    </div>
    <div class="col-xl-3 col-md-6">
        <div class="stat-card">
            <div class="stat-icon" style="color: var(--ace-info);">
                <i class="bi bi-globe"></i>
            </div>
            <div class="stat-number" style="color: var(--ace-info);">@Model.Count(p => p.Type == "iis")</div>
            <div class="stat-label">IIS应用</div>
        </div>
    </div>
    <div class="col-xl-3 col-md-6">
        <div class="stat-card">
            <div class="stat-icon" style="color: var(--ace-warning);">
                <i class="bi bi-gear-fill"></i>
            </div>
            <div class="stat-number" style="color: var(--ace-warning);">@Model.Count(p => p.Type == "service")</div>
            <div class="stat-label">Windows服务</div>
        </div>
    </div>
    <div class="col-xl-3 col-md-6">
        <div class="stat-card">
            <div class="stat-icon" style="color: var(--ace-success);">
                <i class="bi bi-building"></i>
            </div>
            <div class="stat-number" style="color: var(--ace-success);">@Model.GroupBy(p => p.DepartmentId).Count()</div>
            <div class="stat-label">部门数</div>
        </div>
    </div>
</div>

@if (Model.Any())
{
    <div class="card-ace">
        <div class="card-header">
            <i class="bi bi-table me-2"></i>产品列表
            <span class="badge badge-ace-secondary ms-2">@ViewBag.TotalCount 个产品</span>
            @if (ViewBag.DepartmentId != null)
            {
                var selectedDept = (ViewBag.Departments as List<UpdaterManagement.Models.Department>)?.FirstOrDefault(d => d.Id == ViewBag.DepartmentId);
                if (selectedDept != null)
                {
                    <span class="badge badge-ace-info ms-2">部门: @selectedDept.Name</span>
                }
            }
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-ace mb-0">
                    <thead>
                        <tr>
                            <th>产品名称</th>
                            <th>产品说明</th>
                            <th>所属部门</th>
                            <th>负责人</th>
                            <th>部署类型</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model)
                        {
                            <tr>
                                <td>
                                    <strong class="text-dark">@item.Name</strong>
                                </td>
                                <td>
                                    @if (!string.IsNullOrEmpty(item.Description))
                                    {
                                        <span>@item.Description</span>
                                    }
                                    else
                                    {
                                        <span class="text-muted">无说明</span>
                                    }
                                </td>
                                <td>
                                    <span class="badge badge-ace-secondary">@(item.Department?.Name ?? "未知")</span>
                                </td>
                                <td>
                                    <strong>@(item.Department?.Manager ?? "未知")</strong>
                                </td>
                                <td>
                                    @if (item.Type == "iis")
                                    {
                                        <span class="badge badge-ace-info">
                                            <i class="bi bi-globe me-1"></i>IIS站点
                                        </span>
                                    }
                                    else
                                    {
                                        <span class="badge badge-ace-warning">
                                            <i class="bi bi-gear-fill me-1"></i>Windows服务
                                        </span>
                                    }
                                </td>
                                <td>
                                    <small class="text-muted">@item.CreatedTime.ToString("yyyy-MM-dd")</small>
                                </td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <a href="/Product/Edit/@item.Id" class="btn btn-outline-primary btn-sm" title="编辑产品">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        <form method="post" action="/Product/Delete/@item.Id" class="d-inline">
                                            <button type="button" class="btn btn-outline-danger btn-sm" title="删除产品" 
                                                    onclick="showDeleteConfirm('@item.Name', this.form)">
                                                <i class="bi bi-trash"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
        
        <partial name="_Pagination" />
    </div>
}
else
{
    <div class="text-center py-5">
        <div class="mb-3">
            <i class="bi bi-inbox" style="font-size: 48px; color: #ccc;"></i>
        </div>
        <h5 class="text-muted">暂无产品数据</h5>
        <p class="text-muted">请点击上方按钮添加第一个产品</p>
        <a href="/Product/Create" class="btn btn-ace-primary">
            <i class="bi bi-plus-circle me-2"></i>立即添加
        </a>
    </div>
}